import { createStore, Store } from 'vuex';
import { InjectionKey } from 'vue';
import * as typeds from './types';

const files = import.meta.globEager('./modules/*.ts');
const modules = {};

Object.keys(files).forEach(key => {
    const name = key.replace(/(\.\/|\.ts)/g,'')
    modules[name.replace('modules/','')] = files[key].default;
})

export const key: InjectionKey<Store<any>> = Symbol()

export default createStore<any>({
    state() {
        return {
            userName: ''
        }
    },
    mutations: {
        [typeds.SAVE_USERNAME](state, playload) {
            state.userName = playload.userName;
        }
    },
    actions: {},
    getters: {
        getterUserName(state) {
            return state.userName;
        }
    },
    modules
})